package org.particles.gui.statistic;

import java.awt.event.ActionEvent;

import javax.swing.ImageIcon;

import org.particles.gui.AbstractSimAction;
import org.particles.gui.SimCtrlPanel;

/**
 * updates statistic, repaints diagram.
 * first set all necessary properties (commonService, simCtrlPanel)
 * then call initAction method.
 */
public class UpdateStatisticAction extends AbstractSimAction {
	private static final long serialVersionUID = 8341424640107679835L;
	private SimCtrlPanel simCtrlPanel;

	public UpdateStatisticAction() {

	}
	
	/**
	 * must be called after property commonService is set.
	 */
	public void initAction() {
		putValue(SHORT_DESCRIPTION, "Update statistic");
		putValue(SMALL_ICON, new ImageIcon(getCommonService().findImageUrlByName("Refresh16")));
		putValue(LARGE_ICON_KEY, new ImageIcon(getCommonService().findImageUrlByName("Refresh24")));
		putValue(NAME, "Update");
	}
	
	@Override
	public synchronized void actionPerformed(ActionEvent e) {
		simCtrlPanel.getCurrentSimulation().updateStatistics();
		for(StatisticPanel panel : simCtrlPanel.getStatisticPanels()) {
			panel.repaintStatistic();
		}
	}

	public void setSimCtrlPanel(SimCtrlPanel simCtrlPanel) {
		this.simCtrlPanel = simCtrlPanel;
	}

}
